package com.example.qianjun.gobang01.util;

import com.example.qianjun.gobang01.abs.AIPlayer;
import com.example.qianjun.gobang01.bean.Constant;
import com.example.qianjun.gobang01.bean.GobangCheckboard;
import com.example.qianjun.gobang01.robot_player.NovicePlayer;
import com.example.qianjun.gobang01.robot_player.SmartLevelFirst;
import com.example.qianjun.gobang01.robot_player.SmartLevelFourth;
import com.example.qianjun.gobang01.robot_player.SmartLevelSecond;
import com.example.qianjun.gobang01.robot_player.SmartLevelThird;

/**
 * Created by qianjun on 2016/5/2.
 */
public class ReferenceInit {

    public static GobangCheckboard gobangCheckboard;
    public static AIPlayer robotPlayer;
    public static GobangUtil gobangUtil;
    public static int initRobotLevel = Constant.ROBOT_LEVEL_FIRST;

    public static void init(int table_x, int table_y, int robotLevel) {
        gobangCheckboard = new GobangCheckboard(table_x, table_y);
        gobangUtil = new GobangUtil(table_x, table_y, gobangCheckboard.getTable());
        initRobotLevel = robotLevel;
        getAIPlayerInstance(robotLevel);

    }


    public static GobangCheckboard getGobangCheckboard() {
        return gobangCheckboard;
    }

    public static void setGobangCheckboard(GobangCheckboard gobangCheckboard) {
        ReferenceInit.gobangCheckboard = gobangCheckboard;
    }


    public static void setGobangUtil(GobangUtil gobangUtil) {
        ReferenceInit.gobangUtil = gobangUtil;
    }

    public static AIPlayer getRobotPlayer() {
        return robotPlayer;
    }

    //根据机器人等级获取对弈机器人
    public static AIPlayer getRobotPlayer(int robotLevel) {
        if (initRobotLevel == robotLevel) {
            return robotPlayer;
        } else {
            return getAIPlayerInstance(robotLevel);
        }
    }

    public static void setRobotPlayer(AIPlayer robotPlayer) {
        ReferenceInit.robotPlayer = robotPlayer;
    }

    public static GobangUtil getGobangUtil() {
        return gobangUtil;
    }

    //机器人实例化
    public static AIPlayer getAIPlayerInstance(int robotLevel) {
        switch (robotLevel) {
            case Constant.ROBOT_LEVEL_STUPID:
                robotPlayer = new NovicePlayer();
                break;
            case Constant.ROBOT_LEVEL_FIRST:
                robotPlayer = new SmartLevelFirst();
                break;
            case Constant.ROBOT_LEVEL_SECOND:
                robotPlayer = new SmartLevelSecond();
                break;
            case Constant.ROBOT_LEVEL_THIRD:
                robotPlayer = new SmartLevelThird();
                break;
            case Constant.ROBOT_LEVEL_FOURTH:
                robotPlayer = new SmartLevelFourth();
                break;
        }
        return robotPlayer;
    }
}
